package com.zzw.dao;

import com.zzw.model.Track;
import com.zzw.model.TrackHeatMapInfo;
import com.zzw.model.TrackInfo;
import com.zzw.model.TrackQuery;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface TrackDao {
    @Insert("INSERT INTO a_track (personId, venueId) VALUES (#{personId},#{venueId})")
    int insert(Track track);


    @Select("<script> SELECT CAST(t.createTime AS DATE) AS day ,v.name,count(1) AS count" +
            " FROM a_track  t " +
            " LEFT JOIN a_venue v " +
            " ON t.venueId  = v.id " +
            " WHERE 1 = 1 " +
            " <if test='startDate != null and endDate != null '> " +
            " AND t.time BETWEEN #{startDate} AND #{endDate}  " +
            " </if> " +
            " <if test='venueIds != null '> " +
            " AND venueId IN " +
            " <foreach collection='venueIds' item='item' open='(' close=')' separator=','> " +
            "     #{item}   " +
            " </foreach>" +
            " </if> " +
            " GROUP BY CAST(t.createTime AS DATE),v.name ORDER BY day" +
            "</script> ")
    List<TrackInfo> select(TrackQuery trackQuery);

    @Select("<script> SELECT v.lat,v.lng, COUNT(t.personId) AS count " +
            " FROM  a_venue v " +
            " INNER JOIN a_track t  " +
            " ON v.id = t.venueId " +
            " WHERE 1 = 1 " +
            " <if test='startDate != null and endDate != null '> " +
            " AND t.time between #{startDate} AND #{endDate}  " +
            " </if> " +
            " <if test='venueIds != null '> " +
            " AND venueId IN " +
            " <foreach collection='venueIds' item='item' open='(' close=')' separator=','> " +
            "     #{item}   " +
            " </foreach>" +
            " </if> " +
            " GROUP BY v.id " +
            "</script> ")
    List<TrackHeatMapInfo> selectHeatMap(TrackQuery query);

}
